package com.cheea.associationBss.common;



import com.cheea.associationBss.controller.AdminController;
import com.cheea.associationBss.controller.ArticleController;
import com.cheea.associationBss.controller.IndexController;
import com.cheea.associationBss.controller.MailController;
import com.cheea.associationBss.controller.MessageController;
import com.cheea.associationBss.controller.UploadController;
import com.cheea.associationBss.controller.UserController;
import com.cheea.associationBss.model.Article;
import com.cheea.associationBss.model.Mail;
import com.cheea.associationBss.model.Message;
import com.cheea.associationBss.model.User;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;

public class Config extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("config.properties");
		me.setViewType(ViewType.JSP);
		me.setError404View("/view/error/404.html");
		me.setError500View("/view/error/500.html");
	}

	@Override
	public void configRoute(Routes me) {
		//路径映射 
		me.add("/", IndexController.class,"/view/index");
		me.add("/article", ArticleController.class,"/view/article");
		me.add("/upload", UploadController.class,"/view/index");
		me.add("/user", UserController.class,"/view/user");
		me.add("/admin", AdminController.class,"/view/admin");
		me.add("/message", MessageController.class,"/view/admin");
		me.add("/mail", MailController.class,"/view/admin");
	}

	@Override
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
//		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"),getProperty("user"),getProperty("password").trim());
//		me.add(c3p0Plugin);
		
		DruidPlugin dp = new DruidPlugin(getProperty("jdbcUrl"),getProperty("user"),getProperty("password").trim());
		me.add(dp);
		
		// 配置ActiveRecord插件
		//ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		arp.addMapping("article", Article.class); // 映射user表到User模型
		arp.addMapping("user", User.class); // 映射user表到User模型
		arp.addMapping("message", Message.class);
		arp.addMapping("mail", Mail.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		//me.add(new ContextPathHandler("base_path"));
		me.add(new ContextPathHandler());
	}
	
}
